<?php

namespace Biz\Transformers\Site;

use Lumen\Http\Resources\Json\Resource;

/**
 * OrderRegistrationFeeTransformer.
 *
 * @license [http://www.85do.com] [杭州永奥网络科技有限公司]
 * @copyright Copyright (c) 2018-2026 Hangzhou Yongao Technology Co., Ltd. All rights reserved.
 */
class OrderRegistrationFeeTransformer extends Resource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'uid'                         => $this->uid,
            'fee_name'                    => $this->fee_name,
            'registration_no'             => $this->registration_no,
            'price'                       => money_format('%i', $this->price),
            'accompany_price'             => money_format('%i', $this->accompany_price),
            'accompany_number'            => $this->accompany_number,
            'remark'                      => $this->remark,
            'created_at'                  => $this->created_at->getTimestamp(),
            $this->mergeWhen($this->relationLoaded('order'), [
                'order' => $this->getOrderTransformer(),
            ]),
        ];
    }

    /**
     * Get app resource.
     *
     * @return OrderTransformer|null
     */
    public function getOrderTransformer()
    {
        if ($this->relationLoaded('order')) {
            return new OrderTransformer($this->order);
        }

        return null;
    }
}
